home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #11
/
Amiga Plus CD - 2004 - No. 11.iso
/
AmiSoft
/
Dev
/
misc
/
LOCCounter.lha
/
LOCCounter
/
src
/
ArgParser.cpp
next >
Wrap
C/C++ Source or Header
|
2004-08-17
|
2KB
|
90 lines
/****************************************************************************
*
* $RCSfile: ArgParser.cpp $
* $Revision: 2.6 $
* $Date: 2004/08/17 21:53:22 $
* $Author: ssolie $
*
*****************************************************************************
*
* Copyright (c) 2004 Steven Solie. All Rights Reserved.
*
*****************************************************************************
*
* Argument parser
*/
#include "ArgParser.h"
#include <dos/rdargs.h>
#include <proto/dos.h>
ArgParser::ArgParser() :
m_args(0),
m_dos_template(0),
m_strings(0)
{
for ( uint32 i = 0; i < MAX_TEMPLATE_ITEMS; ++i ) {
m_results[i] = 0;
}
}
ArgParser::~ArgParser()
{
IDOS->FreeArgs(m_args);
}
bool ArgParser::parse(const char* dos_template)
{
m_args = reinterpret_cast<RDArgs*>(
IDOS->ReadArgs(const_cast<STRPTR>(dos_template), m_results, 0));
if ( m_args == 0 ) {
return false;
}
else {
m_dos_template = dos_template;
return true;
}
}
bool ArgParser::getBoolean(const char* arg, bool def)
{
bool value = def;
int32 i = IDOS->FindArg(const_cast<STRPTR>(m_dos_template),
const_cast<STRPTR>(arg));
if ( i >= 0 && m_results[i] != 0 ) {
value = true;
}
return value;
}
char* ArgParser::firstString(const char* arg)
{
int32 i = IDOS->FindArg(const_cast<STRPTR>(m_dos_template),
const_cast<STRPTR>(arg));
if ( i < 0 || m_results[i] == 0 ) {
return 0;
}
// Now points to an array of strings.
m_strings = reinterpret_cast<char**>(m_results[i]);
char* string = *m_strings;
return string;
}
char* ArgParser::nextString()
{
++m_strings;
char* string = *m_strings;
return string;
}